# build release version of testbed app

# external control variables:
#
# L3DS_INC_PATH							-- path to lib3ds includes
# L3DS_LIB_PATH							-- path to lib3ds binaries
# HOSTTYPE								-- same as target's HOSTTYPE
# GLSL_QUIRK_ARRAY_PRINCIPAL_ELEMENT	-- uniform arrays are to be referred to in their entirety as the name of their principal element, i.e. 'xxx[0]', rather than 'xxx'
# GLSL_QUIRK_UNINDEXED_SOLE_ELEMENT		-- the sole element of an array of length one is to be referred to as 'yyy', rather than 'yyy[0]'
# GL_USE_MAPBUFFER						-- allow user-space-mapped attribute buffers
# PLATFORM								-- one of: 'pandora', etc.

TARGETS = testbed

UNAME := $(shell uname)
UNAME_P := $(shell uname -p)
UNAME_M := $(shell uname -m)

ifeq ($(GL_USE_MAPBUFFER), 1)
	CFLAGS += -DGL_USE_MAPBUFFER
	SRCS = main.cpp rendCameraVisual.cpp rendBoxVisual.cpp rendColor.cpp rendMaterial.cpp rendRegister.cpp rendCamera.cpp rendLight.cpp rendAttrBuffer.cpp rendAttrBufferMapped.cpp rendMesh.cpp rendSystem.cpp rendSkeleton.cpp
else
	SRCS = main.cpp rendCameraVisual.cpp rendBoxVisual.cpp rendColor.cpp rendMaterial.cpp rendRegister.cpp rendCamera.cpp rendLight.cpp rendAttrBuffer.cpp rendMesh.cpp rendSystem.cpp rendSkeleton.cpp
endif

OBJS = $(SRCS:.cpp=.o)

CC = g++
CFLAGS += -pipe -fmessage-length=0 -fno-rtti -O2 -funroll-loops -ffast-math -fstrict-aliasing -Wtrigraphs -Wreturn-type -Wunused-variable -Wunused-value -DNDEBUG
#CFLAGS += -pipe -fmessage-length=0 -fno-rtti -O0 -g -ffast-math -fstrict-aliasing -Wtrigraphs -Wreturn-type -Wunused-variable -Wunused-value -DDEBUG

ifdef L3DS_INC_PATH
	CFLAGS += -I"$(L3DS_INC_PATH)"
endif
ifdef L3DS_LIB_PATH
	CLINKFLAGS += -L"$(L3DS_LIB_PATH)"
endif

ifeq ($(GLSL_QUIRK_ARRAY_PRINCIPAL_ELEMENT), 1)
	CFLAGS += -DGLSL_QUIRK_ARRAY_PRINCIPAL_ELEMENT
endif

ifeq ($(GLSL_QUIRK_UNINDEXED_SOLE_ELEMENT), 1)
	CFLAGS += -DGLSL_QUIRK_UNINDEXED_SOLE_ELEMENT
endif

ifeq ($(PLATFORM), pandora)
	CC = arm-angstrom-linux-gnueabi-gcc
	CXX = arm-angstrom-linux-gnueabi-g++
	CFLAGS += -DSUPPORT_X11 -marm -mcpu=cortex-a8 -ftree-vectorize -mfloat-abi=softfp -mfpu=neon
	CLINKFLAGS += -lGLESv2 -lEGL -lIMGegl -lsrv_um -lX11 -lXdmcp -lXau
else
	CFLAGS += -marm -mcpu=cortex-a8 -D__USE_XRANDR__
	CLINKFLAGS += -lGLESv2 -lEGL -lX11 -lXrandr
endif

ifneq ($(findstring Darwin, $(UNAME)), Darwin)
	CLINKFLAGS += -lrt
endif

ifeq ($(HOSTTYPE), powerpc)
	CFLAGS += -D__ppc__
else
ifeq ($(HOSTTYPE), arm)
	CFLAGS += -D__arm__
endif
endif

CLINKFLAGS += -l3ds -lstdc++
#CLINKFLAGS += -pg -l3ds -lstdc++

CXXFLAGS = $(CFLAGS)
CXXLINKFLAGS = $(CLINKFLAGS)

BINARIES := $(TARGETS:=$(EXE))

all: $(BINARIES)

$(BINARIES) : $(OBJS)
	$(CC) -o $@ $(OBJS) $(CLINKFLAGS)

clean:
	$(RM) $(BINARIES) $(OBJS)

clobber: clean
	$(RM) *.bak *~

.PHONY: all clean clobber

